/**
 * 登录API服务
 */

interface LoginForm {
  phone: string;
  password: string;
}

interface LoginResponse {
  success: boolean;
  code: number;
  message: string;
  data?: {
    token: string;
    userId: string;
    userName: string;
    phone: string;
  };
}

/**
 * 用户登录
 * @param data 登录表单数据
 * @returns 登录结果
 */
export const login = (data: LoginForm): Promise<LoginResponse> => {
  return new Promise((resolve) => {
    console.log('登录请求参数:', data);
    
    // 模拟网络请求延迟
    setTimeout(() => {
      // 模拟登录成功
      if (data.phone && data.password) {
        resolve({
          success: true,
          code: 200,
          message: '登录成功',
          data: {
            token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiIxMjM0NTYiLCJpYXQiOjE2MTYxMzU1NzgsImV4cCI6MTYxNjE0Mjc3OH0',
            userId: '123456',
            userName: '张三',
            phone: data.phone
          }
        });
      } else {
        // 模拟登录失败
        resolve({
          success: false,
          code: 400,
          message: '用户名或密码错误'
        });
      }
    }, 800);
  });
}; 